﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ASteroids
{
    class HudManager
    {
        private Texture2D texture;
        private Sprite hudFrame;
        private List<Sprite> shieldMarkers;
        private Rectangle screenBounds;
        private SpriteEffects flipp;

        public HudManager(Texture2D texture, Rectangle screenBounds, Vector2 location, SpriteEffects flipp = SpriteEffects.None)
        {
            this.texture = texture;
            this.screenBounds = screenBounds;

            this.flipp = flipp;
            this.hudFrame = new Sprite(location, texture, new Rectangle(16, 304, 210, 67), Vector2.Zero, 1, flipp);
            this.shieldMarkers = new List<Sprite>();
            initHud();
        }

        public void initHud() {
            for (int x = 1; x <= 25; x++) {
                shieldMarkers.Add(new Sprite(new Vector2(81 + x * 5, 8), texture, new Rectangle(240,304,5,20), Vector2.Zero));
            }
        }

        public void Update(GameTime gameTime, int shieldValue)
        {
            int counter = 0;

            foreach(Sprite marker in shieldMarkers)
            {
                marker.Hidden = (counter > shieldValue) ? true : false;
                counter++;
            }
           
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            hudFrame.Draw(spriteBatch);
            foreach (Sprite marker in shieldMarkers) {
                marker.Draw(spriteBatch);
            }
            
        }
    }
}
